package com.example.orders.exception;

import com.example.orders.entity.User;
import com.example.orders.entity.vo.R;
import com.example.orders.feign.MyOpenFeign;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.io.Serializable;

@Component
public class MyFeignFallBack implements FallbackFactory<MyOpenFeign> {
    @Override
    public MyOpenFeign create(Throwable cause) {
        //创建feign接口的匿名内部类对象，重写接口的方法，替换原始的处理逻辑
        return new MyOpenFeign() {
            @Override
            public User selectOne(Serializable id) {
                System.out.println("远程调用失败了，这是兜底的方案==================");
                User user = new User();
                user.setUsername("这是提示，这个对象不能用");

                return user;
            }

        };
    }
}
